package co.yixiang.web.controller.shop;

import co.yixiang.common.annotation.Log;
import co.yixiang.common.core.controller.BaseController;
import co.yixiang.common.core.domain.AjaxResult;
import co.yixiang.common.core.page.TableDataInfo;
import co.yixiang.common.enums.BusinessType;
import co.yixiang.shop.domain.StoreGoods;
import co.yixiang.shop.domain.StoreGoodsImages;
import co.yixiang.shop.domain.StoreGoodsImagesUrl;
import co.yixiang.shop.domain.StoreSpec;
import co.yixiang.shop.service.IStoreGoodImageService;
import co.yixiang.shop.vo.StoreGoodsImagesVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Api(value = "商品图片")
@Controller
@RequestMapping("/shop/goods_image")
public class StoreGoodsImageController extends BaseController {

    private String prefix = "shop/image";

    @Autowired
    public IStoreGoodImageService storeGoodImageService;


    ///  跳转到  image
    @RequiresPermissions("shop:goods_image:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/image";
    }



    /**
     * 新增商品规格(独立)
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }


    ///  跳转到  新增图片组image
//    @RequiresPermissions("shop:goods_image:add")
//    @GetMapping()
//    public String image_add()
//    {
//        return prefix + "/add";
//    }

    /**
     * 新增保存商品规格(独立)
     */
    @RequiresPermissions("shop:goods_image:add")
    @Log(title = "商品图片组(独立)", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StoreGoodsImagesVo storeGoodsImagesVo)
    {

        System.out.println("storeGoodsImagesVo"+storeGoodsImagesVo);
        System.out.println("storeGoodsImagesVo"+storeGoodsImagesVo.getImage_name());

        //return toAjax(1);
       return toAjax(storeGoodImageService.insertGoodsImagesVo(storeGoodsImagesVo));
    }


    @ApiOperation("获取图片组列表 lists1")
    @PostMapping("/lists1")
    @RequiresPermissions("shop:image:lists1")
    @ResponseBody
    public TableDataInfo lists1(StoreGoodsImages storeGoodsImages)
    {
        startPage();
        List<StoreGoodsImagesVo> list = storeGoodImageService.list1(storeGoodsImages);
        System.out.println("获取图片组列表 lists1"+list);
        return getDataTable(list);
    }

    @ApiOperation("移除图片组列表 ")
    @PostMapping("/remove")
    @RequiresPermissions("shop:image:remove")
    @ResponseBody
    public AjaxResult remove(Integer id)
    {
        int remove = storeGoodImageService.remove(id);
        return toAjax(remove);
    }

}
